<?php

/**
 * @author @author Samrat Khan & Sadik Sarfaraz - Apr 13, 2013
 */

    require('top.inc.php');
?>
<?php
if(isset($_SESSION['user']) && $_SESSION['user']['utype'] == 1 || $_SESSION['user']['utype'] == 2 || $_SESSION['user']['utype'] == 3 || $_SESSION['user']['utype'] == 4) {
    $sess_cusID = $_SESSION['user']['cus_id'];

    //create new object pass in number of pages and identifier
    $pages = new Paginator(' 50', 'page');
    $total = getCountA('faulties', 'faulties_id', 'cus_id', $sess_cusID, $db);
    $tots = $total[0]['total'];
    $totals = $pages->set_total($tots);
    $limit = $pages->get_limit();
    
    $rows = selectAllWhereA('faulties', $limit, 'cus_id', $sess_cusID, $db);
    
    echo "<h5>Fauty Return Report</h5>";
    echo "<table class=\"row-fluid table table-striped table-bordered\">";
        echo "<tr>";
            echo "<th>" . $faulties['serialno'] . "</th>";
            echo "<th>" . $faulties['project_id'] . "</th>";
            echo "<th>" . $faulties['rma'] . "</th>";
            echo "<th>" . $faulties['pickuprequestdate'] . "</th>";
            echo "<th>" . $faulties['physicallyreceivedate'] . "</th>";
            echo "<th>" . $faulties['productid'] . "</th>";
            echo "<th>" . $faulties['description'] . "</th>";
            echo "<th>" . $faulties['revisionstate'] . "</th>";
            echo "<th>" . $faulties['boxno'] . "</th>";
            echo "<th>" . $faulties['uom'] . "</th>";
            echo "<th>" . $faulties['return_quantity'] . "</th>";
            echo "<th>" . $faulties['manufacturingdate'] . "</th>";
            echo "<th>" . $faulties['faultiesstatus'] . "</th>";
            echo "<th>" . $faulties['siteid'] . "</th>";
            echo "<th>" . $faulties['warehouseid'] . "</th>";
            echo "<th>" . $faulties['employeeid'] . "</th>";
            echo "<th>" . $faulties['docketdate'] . "</th>";
            echo "<th>" . $faulties['faulties_docketnumber'] . "</th>";
            echo "<th>" . $faulties['remarks'] . "</th>";
            echo "<th>" . $faulties['userid'] . "</th>";
            echo "<th>" . $customer_info['cusname'] . "</th>";
            echo "<th>" . $faulties['inserteddate'] . "</th>";
        echo "</tr>";
        foreach ($rows as $row) {
            echo "<tr>";
                echo "<td>". $row['serialno'] ."</td>";
                echo "<td>";
                    echo getName('projects', 'projectname', 'project_id', $row['project_id'], $db);
                    echo "<br/>";
                    $idofcustomer = getName('projects', 'cus_id', 'project_id', $row['project_id'], $db);
                    $customerid = getName('customerinfo', 'cus_id', 'cus_id', $idofcustomer, $db);
                echo "</td>";
                echo "<td>". $row['rma'] ."</td>";
                echo "<td>". $row['pickuprequestdate'] ."</td>";
                echo "<td>". $row['physicallyreceivedate'] ."</td>";
                echo "<td>". $row['productid'] ."</td>";
                echo "<td>". $row['description'] ."</td>";
                echo "<td>". $row['revisionstate'] ."</td>";
                echo "<td>". $row['boxno'] ."</td>";
                echo "<td>". getName('uom', 'measurement', 'uom_id', $row['uom'], $db)  ."</td>";
                echo "<td>". $row['return_quantity'] ."</td>";
                echo "<td>". $row['manufacturingdate'] ."</td>";
                echo "<td>". getName('faultystatus', 'statusname', 'status_id', $row['faultiesstatus'], $db) ."</td>";
                echo "<td>". $row['siteid'] ."</td>";
                echo "<td>". getName('warehouses', 'warehousename', 'warehouse_id', $row['warehouseid'], $db) ."</td>";
                echo "<td>". getName('employee', 'employeename', 'employee_id', $row['employeeid'], $db) ."</td>";
                echo "<td>". $row['docketdate'] ."</td>";
                echo "<td>". $row['faulties_docketnumber'] ."</td>";
                echo "<td>". $row['remarks'] ."</td>";
                echo "<td>". getName('wms_users', 'username', 'id', $row['userid'], $db) ."</td>";
                echo "<td>". getName('customerinfo', 'cusname', 'cus_id', $row['cus_id'], $db) ."</td>";
                echo "<td>". $row['inserteddate'] ."</td>";
            echo "</tr>";
        }
    echo "<table>";
    echo $pages->page_links();
} else {
    header("Location: login.php");
}
?>

<?php
    include ('bottom.inc.php');
?>